home *** CD-ROM | disk | FTP | other *** search
/ Technotools / Technotools (Chestnut CD-ROM)(1993).ISO / lang_c / ansippv2 / assert.h < prev    next >
C/C++ Source or Header  |  1988-09-13  |  2KB  |  64 lines

  1.  
  2. /*
  3. ** ASSERT.H
  4. ** TLIB Keyword "%v %f %w"
  5. ** "5 13-Sep-88,19:07:06 SBW'"
  6. **
  7. ** 09/20/87 sbw Created
  8. ** 09/01/88 sbw The NDEBUG macro worked backwards.
  9. ** 09/12/88 sbw Protect from repeated inclusion.  Include necessary
  10. **              prototypes.
  11. **
  12. ** Distribute this program freely, provided that no charge is made, and that
  13. ** this notice is retained.  To receive the latest version, along with source
  14. ** code, send $15 to the author.  This program may be used for private,
  15. ** non-commercial use only.  For commercial use, contact the author:
  16. **
  17. ** Steven Bruce Williams
  18. ** Brewster Station
  19. ** P.O. Box 8458
  20. ** Bridgeport, CT 06605-0997
  21. **
  22. ** This is an ANSI-conforming implementation if the assert() macro.  This may
  23. ** be used with any K&R C compiler.
  24. */
  25.  
  26. #ifndef assert
  27.  
  28. #ifndef NDEBUG
  29.  
  30. /*
  31. ** STDIO.H must be included to define fprintf().
  32. ** STDLIB.H must be included to define exit().
  33. ** ANSI requires that each of these are protected from repeated inclusion, so
  34. ** it doesn't matter if the source code includes both ASSERT.H and either or
  35. ** both of STDIO.H and STDLIB.H.
  36. */
  37.  
  38. #include <stdio.h>
  39. #include <stdlib.h>
  40.  
  41. #define assert(condition)                                    \
  42.         ((void)(!(condition) ? (fprintf(stderr,              \
  43.                                         "Assertion failed: " \
  44.                                         #condition           \
  45.                                         ", file "            \
  46.                                         __FILE__             \
  47.                                         ", line %u\n",       \
  48.                                         __LINE__             \
  49.                                        ) ,                   \
  50.                                 exit(-1) ,                   \
  51.                                 0                            \
  52.                                )                             \
  53.                              : 0                             \
  54.                )                                             \
  55.         )
  56.  
  57. #else
  58.  
  59. #define assert(ignore)
  60.  
  61. #endif
  62.  
  63. #endif
  64.